Repository navigation
Use the hf auth login token for dataset downloads - #707
Open
vahid-ahmadi wants to merge 1 commit into
Open
vahid-ahmadi wants to merge 1 commit into
vahid-ahmadi wants to merge 1 commit into
Conversation
hugging_face_auth_headers read only HUGGING_FACE_TOKEN, HF_TOKEN and HUGGINGFACE_HUB_TOKEN, so a user who logged in with `hf auth login` got "Hugging Face rejected the configured credentials" although no token was sent. Fall back to huggingface_hub.get_token(), and make the 401/403 message say whether a token was sent and how to request access to the private UK data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vahid-ahmadi
marked this pull request as ready for review
October 23, 2026 21:59
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hugging_face_auth_headers()reads onlyHUGGING_FACE_TOKEN,HF_TOKENandHUGGINGFACE_HUB_TOKEN. A user who follows Hugging Face's own setup (hf auth login) has a valid token saved, butensure_datasets,managed_microsimulationandmaterialize_datasetsend no token and then report:No credentials were configured, so the message points the wrong way, and it does not say how to get access to the private UK data.
Changes:
huggingface_hub.get_token()(thehf auth logintoken) when none of the environment variables is set. The environment variables keep precedence.huggingface_hubcomes in through policyengine-core; the import is guarded.hugging_face_auth_failure(), builds the 401/403 message for both download paths (bundle datasets and explicithf://URIs). It says either "no Hugging Face credentials were found" or "rejected the configured credentials", names both ways to supply a token, and gives the access route from the policyengine-uk getting-started guide (email contact@policyengine.org with the Hugging Face username and evidence of UK Data Service access).Found while reproducing a published think-tank energy-bill targeting analysis on Microcosm UK 2024-25 as a new user with only the public docs.
Evidence
On 6.10.1 with a valid
hf auth loginand no token environment variables,pe.uk.ensure_datasets(datasets=["microcosm_uk_2024_25"], years=[2024])fails with the message above. With this branch,hugging_face_auth_headers()returns the saved token, and a HEAD request for the pinnedmicrocosm_uk_2024_25.h5returns 302 (redirect to the file) instead of 401.Tests
tests/test_dataset_materialization.pygains four tests: the CLI login is used when no environment variable is set; an environment token takes precedence; a 401 without a token says none was found and gives the access route; a 403 with a token says it was rejected and does not echo the token. The first three fail on main; all 17 tests in the file pass here, as dotests/test_release_manifests.pyandtests/test_dataset_source.py.ruff checkandruff format --checkpass on the changed files.🤖 Generated with Claude Code